package com.vanysoft.business.system.operateLogs.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.vanysoft.business.system.operateLogs.dao.TSystemApiAccessLogsMapper;
import com.vanysoft.business.system.operateLogs.entity.TSystemApiAccessLogs;
import com.vanysoft.framework.exception.VanySoftBaseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 类名称：SystemApiAccessLogsService
 * 类描述：接口日志操作业务类
 * 创建人：X
 * 创建时间：2017年9月19日下午5:49:23
 * 修改人：X
 * 修改时间：2017年9月19日
 * 版本信息：@version 1.0
 * Copyright (c) 2017SharpClaw-版权所有
 * 修改备注：
 */
@Service
@Transactional(readOnly = true)
public class SystemApiAccessLogsService {


    @Autowired
    private TSystemApiAccessLogsMapper tSystemApiAccessLogsMapper;

    /**
     * Function Name               loginValidate
     *
     * @return
     * @throws VanySoftBaseException
     * @description 分页查询操作日志方法
     * Modify History:              Date             Programmer       Notes
     * ---------        ---------------  ---------
     * 2017年9月12日下午8:10:03          KING          Initial
     * *********************************************************************
     */
    public Map<String, Object> querySystemApiAccessLogs(Integer pageSize, Integer pageNum, String Timevalue, String searchValue, String value1) throws VanySoftBaseException {
        Map<String, Object> operateLogs = new HashMap<String, Object>();
        String beginTime = "";
        String endTime = "";
        if (Timevalue != null && !"".equalsIgnoreCase(Timevalue)) {
            String[] times = Timevalue.split(";");
            beginTime = times[0];
            endTime = times[1];
        }
        //分页工具
        Page<Map<String, Object>> page = new Page<>(pageNum, pageSize);
        List<TSystemApiAccessLogs> list = tSystemApiAccessLogsMapper.querySystemApiAccessLogs(page, beginTime, endTime, searchValue, value1);
        //int forBidden = tSystemUserLogsMapper.queryForbiddenOperateLogs(beginTime, endTime, searchValue,value1);
        //int NotForBidden = tSystemUserLogsMapper.queryNotForbiddenOperateLogs(beginTime, endTime, searchValue,value1);
        operateLogs.put("rows", list);
        operateLogs.put("total", page.getTotal());
        //users.put("forBidden", forBidden);
        //users.put("NotForBidden", NotForBidden);
        return operateLogs;
    }

    /**
     * 获取导出日志EXCEL数据方法
     * Function Name               loginValidate
     *
     * @return
     * @throws VanySoftBaseException
     * @description 系统登录API
     * Modify History:              Date             Programmer       Notes
     * ---------        ---------------  ---------
     * 2017年11月18日下午11:25:18          KING          Initial
     * *********************************************************************
     */
    public List<TSystemApiAccessLogs> queryLogsForExcel(String Timevalue, String searchValue, String value1) throws VanySoftBaseException {
        String beginTime = "";
        String endTime = "";
        if (Timevalue != null && !"".equalsIgnoreCase(Timevalue)) {
            String[] times = Timevalue.split(";");
            beginTime = times[0];
            endTime = times[1];
        }
        return tSystemApiAccessLogsMapper.querySystemApiAccessLogs(beginTime, endTime, searchValue, value1);
    }


    @Transactional
    public void insertSystemApiAccessLogs(TSystemApiAccessLogs obj) throws VanySoftBaseException {
        tSystemApiAccessLogsMapper.insertSystemApiAccessLog(obj);
    }

    @Transactional
    public void updateSystemApiAccessLogs(TSystemApiAccessLogs obj) throws VanySoftBaseException {
        tSystemApiAccessLogsMapper.updateSystemApiAccessLog(obj);
    }

    public TSystemApiAccessLogs selectById(String id) {
        return tSystemApiAccessLogsMapper.selectById(id);
    }
}
